<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Kingsemi AMS</title>
	<link rel="stylesheet" href="js/easyui/themes/bootstrap/easyui.css">
	<link rel="stylesheet" href="js/easyui/themes/icon.css">
	<link rel="stylesheet" href="css/index-ui.css" />
	<script type="text/javascript" src="js/easyui/jquery.min.js"></script>
	<script type="text/javascript" src="js/easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="js/ams.util.js"></script>
	<script type="text/javascript" src="js/webapi.js"></script>
	<script type="text/javascript" src="js/jquery.time.js"></script>
	<script type="text/javascript" src="js2/loginCookies.js"></script>
</head>
<body onload="on_page_load()" bgcolor="#999999">
	<div data-options="region:'north'" class="index-top">
		<div class="index-top-content">
			<div class="index-top-logo">
				<p><img src="img/logo.png" alt="" /></p>
			</div>
			<span style="float:left;font-size:22px;color:#ffffff;margin:20px">Automated Monitoring System</span>
			<span id="index_top_login" style="cursor:pointer" onclick="Logout()"> Logout </span>
		</div>
	</div>

	<div id="div-index-top-info"> &nbsp;
		<p id='p_sys_rev' style="float:left;color:#777777;padding-left:3px"> System Revision: 1.0.0.1 </p>
		<div style="float:right;color:#777777;padding-right:3px">
			<span id="span_clock_show"></span>
		</div>
	</div>

	<div id="cc" class="easyui-layout box">
		<div data-options="region:'west',split:true" title="System Explorer" style="width:200px;">
			<ul id="index_left_tree" class="easyui-tree"></ul>
		</div>
		<div class="index_pane_main" data-options="region:'center',title:'AMS System'">
			<div class="iframe-box">
				<iframe scrolling="no" height="700" name="index_main_area" src="overview/intro.html" frameborder="0"></iframe>
			</div>
		</div>
	</div>
<!--
	<div data-options="region:'north'" class="index-bottom">
		<div class="index-bottom-content">
			<span style="float:left;font-size:22px;color:#ffffff;margin:20px">www.kingsemi.com</span>
		</div>
	</div> -->
</body>
<script type="text/javascript">
var left_tree_data = []
function __update_tree(json_data)
{
	for (var i = 0; i < json_data.length; i++) {
		var rootNode = {};
		var grpName = json_data[i]['group_name'];
		var grpId = json_data[i]['group_id'];				
		rootNode['text'] = grpName;
		rootNode['href'] = 'overview/group_overview.html?group=' + grpName;
		var json_devs = json_data[i]['eq_array'];
		var eqNodeArray = [];
		for (var k = 0; k < json_devs.length; k++) {
			var eqNode = {};
			eqNode['text'] = json_devs[k]['name']
			eqNode['href'] = 'equipment/equipment.html?eq=' + json_devs[k]['name'] + "#" + grpName
			eqNode['iconCls'] = 'icon-eq'
			eqNodeArray.push(eqNode)
		}
		rootNode['children'] = eqNodeArray
		left_tree_data.push(rootNode)
	}

    acquiescent();
    
}

function acquiescent(){
     
	// left_tree_data.push(
	// 	{text: 'Statistic', 
	// 	href: '',
	// 	children: [{
	// 		text: 'Equipment Time',
	// 		href: ''				
	// 	},{
	// 		text: 'Alarm',
	// 		href: ''
	// 	}]}
	// //	{text: 'Statistic', href: 'stat/stat.html'}
	// );

	left_tree_data.push(
		{text: 'System Settings', 
		href: '',
		children: [{
			text: 'Equipment Management',
			href: 'System-Settings/eq_management.html'				
		},{
			text: 'User Management',
			href: 'System-Settings/user_management.html'
		}]},
		{text: 'System Help', 
		href: '',
		children: [{
			text: 'User Manual',
			href: 'docs/UserManual.pdf'
		}]}
	);

	$('#index_left_tree').tree({
		data: left_tree_data,
		onClick: function(node){
			// console.log(node)
			var href = node.href;
			// do more thing with href
		//	alert(href);
			window.open(href, 'index_main_area');
		}
	})
}

function on_page_load()
{
	if (ams_is_sim_mode()) {
		$.getJSON("group_eq_cfg.json", function(json_data){
			__update_tree(json_data)
		})
	} else {
		// if (GetCookie('user_level') == null) {
		if (GetCookie('ams_user_level') == null || GetCookie('ams_user_name') == null) {
    		window.location.href='http://' + window.location.host;
		return;}
	document.getElementById("index_top_login").innerText="Login:" + GetCookie('ams_user_name');  
		$.ajax({
			type: 'POST',
			contentType: 'application/json',
			url: getWebServiceUrl("getEqGroupList"),
			data:JSON.stringify({
				
			}),
			dataType: 'json',
			success: function (json_data) {
				console.log(JSON.parse(json_data.d))
				__update_tree(JSON.parse(json_data.d))
			},
			error: function (response) {
				//alert(errorThrown.message);
				alert('Error: ' + response.responseText)
				acquiescent()
			}
		});
	}

	clock_run()
}

function Logout()
{
	$.messager.confirm('AMS System',
	'Are you sure to logout?',
	function(r) {
		if (r){
			Delcookie("user_level");
			window.location.href='http://' + window.location.host;
	}})
}
</script>
</html>
